package com.tool;

import com.tool.entity.LoginUser;

/**
 * @author niuyicong
 * @date 2024/10/22  22:41:42
 * @description
 */
public class ThreadLocalDemo {

    InheritableThreadLocal inheritableThreadLocal = new InheritableThreadLocal();

    private static ThreadLocal<LoginUser> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) {
        LoginUser loginUser = new LoginUser();
        loginUser.setUserId("123456");
        loginUser.setUserName("niuxiaoniu");
        threadLocal.set(loginUser);
        subM1();
    }

    public static void subM1(){
        System.out.println("调用子方法1...");
        subM2();
    }

    public static void subM2(){
        System.out.println("调用子方法2...");
        LoginUser loginUser = threadLocal.get();
        System.out.println("userId：" + loginUser.getUserId() + ",  userName：" + loginUser.getUserName());
    }
}
